<template>
    <div class="todo-list">
        <h2>Todo List</h2>
        <input placeholder="Add a new todo" v-model="a1">
        <button @click="add">Add</button>
        <ul>
            <li v-for="(item, index) in a" @click="del(index)" :key="index">{{ item }}</li>
        </ul>
    </div>
</template>

<script setup lang='ts'>
import { reactive, ref } from 'vue';


const a = reactive(['Sample Todo 1', 'Sample Todo 2', 'Sample Todo 3'])
const a1 = ref('')
function add() {
    if (a1.value == '') {
        a.push(`Sample Todo ${a.length + 1}`)
    } else {
        a.push(a1.value)
    }

    a1.value = ''
}
function del(index: number) {
    a.splice(index, 1)
}
</script>

<style>
.todo-list {
    text-align: center;
}

input {
    padding: 5px;
    margin-right: 10px;
}

button {
    padding: 5px;
    background-color: #2196f3;
    color: white;
    border: none;
    cursor: pointer;
}

button:hover {
    background-color: #0b7dda;
}

ul {
    list-style: none;
    padding: 0;
}

li {
    cursor: pointer;
    padding: 10px;
    margin: 5px 0;
    background-color: #f1f1f1;
}

li:hover {
    background-color: #ddd;
}
</style>
